﻿/*
 * User: David
 * Date: 29/06/2013
 * Time: 3:10 PM
 * 
 */
using System;
using System.Collections.Generic;
using HockeySimulator.Interfaces;

namespace HockeySimulator.Entities.League
{
	/// <summary>
	/// Description of Conference.
	/// </summary>
	public class Conference:iExportable
	{
		private string Name;
		private List<Division> Divisions;
		
		//Constructors
		public Conference(bool UseDefaultInitialize = false)
		{
			if(UseDefaultInitialize)
				defaultConferenceInitialize();
			else
			{
				Name = "";
				Divisions = new List<Division>();
			}
				
		}
		
		public Conference (List<Division> DivisionList, string ConferenceName = "")
		{
			Name = (ConferenceName!= null?ConferenceName:"");
			
			if (DivisionList.Count > 0)
				Divisions = new List<Division>(DivisionList);
			else
				Divisions = new List<Division>();
		}
		
		private void defaultConferenceInitialize()
		{
			Name = "DefaultConferenceName";
			Divisions = new List<Division>();
			
			AddDivision(new Division(true));
		}
		
		//Interface method
		
		public string Export()
		{
			string NL = Environment.NewLine;
			
			string result = "Conference : " + Name + NL;
			result += "-------------------------" + NL;
			
			if (Divisions != null)
			{
				if(Divisions.Count == 0)
					result += "No divisions";
				else
				{
					foreach (Division D in Divisions)
					{
						result += D.Export() + NL;
						result += "-------------------------" + NL;
					}
				}
			}
			else
			{
				result += "No divisions";
			}
			
			return result;
		}
		
		//Other Methods
		public void AddDivision(Division D)
		{
			//TODO Throw an error if null
			if(Divisions != null)
				Divisions.Add(D);
		}
		
		public void ReinitializeDivisions()
		{
			Divisions = new List<Division>();
		}
	}
}
